package edu.neu.swc.skynet.controller;

import edu.neu.swc.skynet.common.SearchParams;
import edu.neu.swc.skynet.common.TableId;
import edu.neu.swc.skynet.movie.MovieInfo;
import edu.neu.swc.skynet.movie.MovieShow;
import edu.neu.swc.skynet.service.IMovieService;
import edu.neu.swc.skynet.vo.PageMovieShow;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>Movie服务对外接口</h1>
 * 对外提供RESTful接口
 */
@Slf4j
@RestController
@RequestMapping("/movie")
@Api(tags = "电影微服务对外暴露HTTP接口")
public class MovieController {

    private final IMovieService movieService;

    public MovieController(IMovieService movieService) {
        this.movieService = movieService;
    }

    @ApiOperation(value = "电影详细信息",
            notes = "根据 TableId 查询电影详细信息",
            httpMethod = "POST"
    )
    @PostMapping("/movie-info")
    public List<MovieInfo> getMovieInfoByTableId(
            @RequestBody TableId tableId
    ){
        return movieService.getMovieInfoByTableId(tableId);
    }

    @ApiOperation(value = "电影展示信息",
            notes = "根据 TableId 查询电影展示信息",
            httpMethod = "POST"
    )
    @PostMapping("movie-show")
    public List<MovieShow> getMovieShowByTableId(
            @RequestBody TableId tableId
    ){
        return movieService.getMovieShowByTableId(tableId);
    }

    @ApiOperation(value = "电影展示信息",
            notes = "分页查询电影展示信息，默认为 page 1",
            httpMethod = "GET"
    )
    @GetMapping("/page-movie-show")
    public PageMovieShow getMovieShowByPage(
            @RequestParam(required = false, defaultValue = "1") int page
    ){
        return movieService.getMovieShowByPage(page);
    }

    @ApiOperation(value = "搜索电影",
            notes = "根据关键字搜索电影",
            httpMethod = "POST"
    )
    @PostMapping("/search-page-movie-show")
    public PageMovieShow searchMovieByPage(
            @RequestBody SearchParams searchParams
    ){
        return movieService.searchMovieShowByPage(searchParams);
    }
}
